package com.linkoog.devtools.http.request.http_request.request_body.body.text;

import com.intellij.openapi.project.Project;
import com.linkoog.devtools.http.request.common.request_body.text.PlainTextRequestBody;
import com.linkoog.devtools.http.request.http_request.request_body.BodyPanel;
import com.linkoog.devtools.intellij.editor.PlainTextEditerPanel;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

public class PlainTextBodyPanel extends PlainTextEditerPanel implements BodyPanel<PlainTextRequestBody> {

    public PlainTextBodyPanel(@NotNull Project project) {
        super(project);
    }

    public PlainTextBodyPanel(@NotNull Project project, String text) {
        super(project, text);
    }

    public void resetRequestBody(@NotNull PlainTextRequestBody requestBody) {
        setEditorText(requestBody.getValue());
    }

    public @NotNull PlainTextRequestBody buildRequestBody() {
        return PlainTextRequestBody.of(getEditorText());
    }

    @Override
    public JPanel getPanel() {
        return this;
    }
}
